<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="客户名称" prop="customerName">
        <el-input v-model="queryParams.customerName" placeholder="请输入客户名称" clearable style="width: 150px" />
      </el-form-item>
      <el-form-item label="客户编码" prop="customerCode">
        <el-input v-model="queryParams.customerCode" placeholder="请输入客户编码" clearable style="width: 150px" />
      </el-form-item>
      <el-form-item label="表号" prop="meterCode">
        <el-input v-model="queryParams.meterCode" placeholder="请输入表号" clearable style="width: 150px" />
      </el-form-item>
      <el-form-item label="手机号" prop="telephone">
        <el-input v-model="queryParams.telephone" placeholder="请输入手机号" clearable style="width: 150px" />
      </el-form-item>
      <el-form-item label="IMEI" prop="imei">
        <el-input v-model="queryParams.imei" placeholder="请输入IMEI" clearable style="width: 150px" />
      </el-form-item>
      <el-form-item label="计价方案" prop="priceSchemeId">
        <el-select v-model="queryParams.priceSchemeId" filterable placeholder="请选择">
          <el-option :label="item.schemeName" :value="item.id" v-for="(item, index) in schemeList" :key="index">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="小区名称" prop="areaName">
        <el-input v-model="queryParams.areaName" placeholder="请输入小区名称" clearable style="width: 150px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:meterarchives:add']">新增</el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"-->
      <!--          v-hasPermi="['system:meterarchives:remove']">删除</el-button>-->
      <!--      </el-col>-->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:meterarchives:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="postList" border @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="客户名称" align="center" prop="customerName" />
      <el-table-column label="客户编码" align="center" key="customerCode" prop="customerCode" :show-overflow-tooltip="true" />
      <el-table-column prop="status" label="客户类型" width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.customer_type" :value="scope.row.customerType" />
        </template>
      </el-table-column>
      <el-table-column label="计价方案" align="center" key="priceSchemeName" prop="priceSchemeName"
                       :show-overflow-tooltip="true" width="150"/>
      <el-table-column label="表号" align="center" prop="meterCode" width="120" />
      <el-table-column label="表计状态" align="center" prop="meterStatus" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.meterStatus == 1">待安装</span>
          <span v-if="scope.row.meterStatus == 2">已安装</span>
          <span v-if="scope.row.meterStatus == 3">已拆卸</span>
        </template>
      </el-table-column>
      <el-table-column label="激活状态" align="center" prop="activeStatus" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.activeStatus == 'N'">未激活</span>
          <span v-if="scope.row.activeStatus == 'Y'">已激活</span>
        </template>

      </el-table-column>
      <el-table-column label="阀门状态" align="center" prop="valveStatus" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.valveStatus == 0">关闭</span>
          <span v-if="scope.row.valveStatus == 1">开启</span>
          <span v-if="scope.row.valveStatus == 2">未知</span>
        </template>

      </el-table-column>


      <el-table-column label="供应商" align="center" prop="meterManufacturer" width="120" />
      <!--      <el-table-column label="基表手机号" align="center" prop="meterPhoneNum" width="120" />-->
      <el-table-column label="表计类型" align="center" prop="meterType" width="150" />
      <el-table-column label="证件号" align="center" key="idNumber" prop="idNumber" :show-overflow-tooltip="true"
        width="100" />
      <el-table-column label="联系电话" align="center" key="telephone" prop="telephone" :show-overflow-tooltip="true"
        width="120" />
      <el-table-column label="客户地址" align="center" key="customerAddress" prop="customerAddress"
        :show-overflow-tooltip="true" />
      <el-table-column label="气表进气方向" align="center" prop="intakeDirection" width="150">
        <template slot-scope="scope">
          <span v-if="scope.row.intakeDirection == 'L'">左进</span>
          <span v-if="scope.row.intakeDirection == 'R'">右进</span>
        </template>
      </el-table-column>
      <el-table-column label="ICCID" align="center" prop="iccid" />
      <el-table-column label="IMEI" align="center" prop="imei" />
      <el-table-column label="DTU编号" align="center" prop="dtuCode" />
      <!-- <el-table-column label="设备ID" align="center" prop="deviceId" /> -->
      <el-table-column label="流量计厂家" align="center" prop="flowmeterManufacturer" width="120" />
      <el-table-column label="基表底数" align="center" prop="baseNumber" />
      <el-table-column label="安装日期" align="center" prop="installTime" width="170" />

      <el-table-column label="报警额度" align="center" prop="alarmGas" />
      <el-table-column label="是否带流量计" align="center" prop="isFlowmeter" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.isFlowmeter == 'N'">否</span>
          <span v-if="scope.row.isFlowmeter == 'Y'">是</span>
        </template>
      </el-table-column>
      <el-table-column label="流量计起始量" align="center" prop="initialGas" width="150" />
      <el-table-column label="是否带GPRS" align="center" prop="isGprs" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.isGprs == 'N'">否</span>
          <span v-if="scope.row.isGprs == 'Y'">是</span>
        </template>
      </el-table-column>

      <el-table-column label="通讯地址" align="center" prop="mailAddress" />
      <el-table-column label="通讯协议" align="center" prop="mailProtocol" />
      <!--      <el-table-column label="工程工料费" align="center" prop="projectFee" width="120" />-->
      <!--      <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="250" fixed="right">
        <template slot-scope="scope">
          <el-button v-if="scope.row.meterStatus != 3" size="mini" type="text" icon="el-icon-edit"
            @click="handleUpdate(scope.row)" v-hasPermi="['system:meterarchives:edit']">修改</el-button>
          <el-button v-if="scope.row.meterStatus != 3" size="mini" type="text" icon="el-icon-delete"
            @click="handleDelete(scope.row)" v-hasPermi="['system:meterarchives:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改岗位对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="客户名称" prop="customerName">
              <el-input v-model="form.customerName" placeholder="请输入客户名称" maxlength="30" disabled>
                <template slot="append"><el-button slot="append" icon="el-icon-search"
                    @click="customerSerch"></el-button></template>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="表号" prop="meterCode">
              <el-input v-model="form.meterCode" placeholder="请输入表号" maxlength="30" :disabled="disStatus" />
              <!-- <el-input v-model="form.meterCode" placeholder="请输入表计编码" maxlength="30" disabled style="width:80%" />
              <i class="el-icon-refresh" @click="refreshNumber" style="cursor: pointer;margin-left: 5px;"></i> -->
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="供应商" prop="meterManufacturer">
              <el-select v-model="form.meterManufacturer" filterable placeholder="请选择" @change="getMeterListBySupplier"
                :disabled="disStatus">
                <el-option :label="item.supplierName" :value="item.id" v-for="(item, index) in supplierList" :key="index">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="表计类型" prop="meterType">
              <el-select v-model="form.meterType" filterable placeholder="请选择" :disabled="disStatus">
                <el-option :label="item.typeName" :value="item.id" v-for="(item, index) in meterBySupplierList"
                  :key="index">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="计价方案" prop="priceSchemeId">
              <el-select v-model="form.priceSchemeId" filterable placeholder="请选择">
                <el-option :label="item.schemeName" :value="item.id" v-for="(item, index) in schemeList" :key="index">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="表计状态" prop="meterStatus">
              <el-select v-model="form.meterStatus" filterable placeholder="请选择">
                <el-option label="待安装" :value="1"> </el-option>
                <el-option label="已安装" :value="2"> </el-option>
                <el-option label="已拆卸" :value="3"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="DTU/RTU编号" prop="dtuCode">
              <el-input v-model="form.dtuCode" placeholder="请输入DTU/RTU编号" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="IMEI" prop="imei">
              <el-input v-model="form.imei" placeholder="请输入imei" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="基表对应ICCID" prop="iccid">
              <el-input v-model="form.iccid" placeholder="请输入基表对应ICCID" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="进气方向" prop="intakeDirection">
              <el-radio-group v-model="form.intakeDirection">
                <el-radio label="L">左进</el-radio>
                <el-radio label="R">右进</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
            <el-form-item label="同步到IOT平台" prop="nickName">
              <el-select v-model="form.nickName" filterable placeholder="请选择">
                <el-option label="否" value="N"> </el-option>
                <el-option label="是" value="Y"> </el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :span="8">
            <el-form-item label="是否带GPRS" prop="isGprs">
              <el-select v-model="form.isGprs" filterable placeholder="请选择">
                <el-option label="否" value="N"> </el-option>
                <el-option label="是" value="Y"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!--          <el-col :span="8">-->
          <!--            <el-form-item label="阀门状态" prop="valveStatus">-->
          <!--              <el-select v-model="form.valveStatus" filterable placeholder="请选择">-->
          <!--                <el-option label="关闭" :value="0"> </el-option>-->
          <!--                <el-option label="开启" :value="1"> </el-option>-->
          <!--                <el-option label="未知" :value="2"> </el-option>-->
          <!--              </el-select>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <el-col :span="8">
            <el-form-item label="安装日期" prop="installTime">
              <el-date-picker v-model="form.installTime" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"
                style="width:100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报警额度" prop="alarmGas">
              <el-input v-model="form.alarmGas" placeholder="请输入报警额度" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="基表底数" prop="baseNumber">
              <el-input v-model="form.baseNumber" placeholder="请输入基表底数" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="通讯地址" prop="mailAddress">
              <el-input v-model="form.mailAddress" placeholder="请输入通讯地址" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="通讯协议" prop="mailProtocol">
              <el-input v-model="form.mailProtocol" placeholder="请输入通讯协议" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否带流量计" prop="isFlowmeter">
              <el-select v-model="form.isFlowmeter" filterable placeholder="请选择">
                <el-option label="否" value="N"> </el-option>
                <el-option label="是" value="Y"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="流量计厂家" prop="flowmeterManufacturer">
              <el-input v-model="form.flowmeterManufacturer" placeholder="请输入流量计厂家" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="流量计起始量" prop="initialGas">
              <el-input v-model="form.initialGas" placeholder="请输入流量计起始量" maxlength="30" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
            <el-form-item label="厂家" prop="meterManufacturer">
              <el-input v-model="form.meterManufacturer" placeholder="请输入气表品牌" maxlength="30" />
            </el-form-item>
          </el-col> -->
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
      <!-- 客户列表弹框 -->
      <el-dialog title="客户列表" :visible.sync="open1" width="900px" append-to-body>
        <el-form :model="queryParams1" ref="queryForm1" size="small" :inline="true" v-show="showSearch"
          label-width="68px">
          <el-form-item label="客户类型" prop="customerType">
            <el-select v-model="queryParams1.customerType" filterable placeholder="请选择">
              <el-option v-for="dict in dict.type.customer_type" :key="dict.value" :label="dict.label"
                :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="客户名称" prop="customerName">
            <el-input v-model="queryParams1.customerName" placeholder="请输入客户名称" clearable style="width: 150px" />
          </el-form-item>

          <el-form-item label="客户编码" prop="customerCode">
            <el-input v-model="queryParams1.customerCode" placeholder="请输入客户编码" clearable style="width: 150px" />
          </el-form-item>
          <el-form-item label="手机号" prop="telephone">
            <el-input v-model="queryParams1.telephone" type="number" placeholder="请输入手机号" clearable
              style="width: 150px" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery1">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery1">重置</el-button>
          </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="userList" border @row-click="rowSelectionChange">
          <el-table-column label="客户名称" align="center" key="customerName" prop="customerName"
            :show-overflow-tooltip="true" />
          <el-table-column label="客户类型" align="center" key="customerType" prop="customerType"
            :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.customer_type" :value="scope.row.customerType" />
            </template>
          </el-table-column>
          <el-table-column label="证件号" align="center" key="idNumber" prop="idNumber" :show-overflow-tooltip="true"
            width="100" />
          <el-table-column label="总购气金额" align="center" key="totalAmout" prop="totalAmout" :show-overflow-tooltip="true"
            width="120" />
          <el-table-column label="余额" align="center" key="remainAmout" prop="remainAmout" :show-overflow-tooltip="true"
            width="100" />
          <el-table-column label="总用气量" align="center" key="totalVolume" prop="totalVolume" :show-overflow-tooltip="true"
            width="120" />
          <el-table-column label="剩余气量" align="center" key="remainVolume" prop="remainVolume"
            :show-overflow-tooltip="true" width="120" />
          <el-table-column label="计费周期开始时间" align="center" key="cycleStartTime" prop="cycleStartTime"
            :show-overflow-tooltip="true" width="100" />
          <el-table-column label="计费周期结束时间" align="center" key="cycleEndTime" prop="cycleEndTime"
            :show-overflow-tooltip="true" />
          <el-table-column label="周期内总用气量" align="center" key="cycleUseGas" prop="cycleUseGas"
            :show-overflow-tooltip="true" />
          <el-table-column label="周期内总使用金额" align="center" key="cycleUseAmount" prop="cycleUseAmount"
            :show-overflow-tooltip="true" />
          <el-table-column label="充值次数" align="center" key="payCount" prop="payCount" :show-overflow-tooltip="true" />
          <el-table-column label="单元号" align="center" key="unit" prop="unit" :show-overflow-tooltip="true" width="100" />
          <el-table-column label="楼栋号" align="center" key="building" prop="building" :show-overflow-tooltip="true" />
          <el-table-column label="楼层号" align="center" key="floor" prop="floor" :show-overflow-tooltip="true" />
          <el-table-column label="门牌号" align="center" key="houseNo" prop="houseNo" :show-overflow-tooltip="true" />
          <el-table-column label="客户地址" align="center" key="customerAddress" prop="customerAddress"
            :show-overflow-tooltip="true" />
          <el-table-column label="账单日" align="center" key="billDay" prop="billDay" :show-overflow-tooltip="true" />
          <el-table-column label="自动发送短信" align="center" key="isAutoSendmsg" prop="isAutoSendmsg"
            :show-overflow-tooltip="true" width="120">
            <template slot-scope="scope">
              <span v-if="scope.row.isAutoSendmsg == 'N'">否</span>
              <span v-if="scope.row.isAutoSendmsg == 'Y'">是</span>
            </template>
          </el-table-column>
          <!-- <el-table-column label="是否加入黑名单" align="center" key="isBlack" prop="isBlack" :show-overflow-tooltip="true"
            width="120">
            <template slot-scope="scope">
              <span v-if="scope.row.isBlack == 'N'">否</span>
              <span v-if="scope.row.isBlack == 'Y'">是</span>
            </template>
          </el-table-column>
          <el-table-column label="是否给客户发送短信" align="center" key="isSendMsg" prop="isSendMsg" :show-overflow-tooltip="true"
            width="150">
            <template slot-scope="scope">
              <span v-if="scope.row.isSendMsg == 'N'">否</span>
              <span v-if="scope.row.isSendMsg == 'Y'">是</span>
            </template>
          </el-table-column> -->
          <el-table-column label="是否欠费关阀" align="center" key="isCloseOverdue" prop="isCloseOverdue"
            :show-overflow-tooltip="true" width="120">
            <template slot-scope="scope">
              <span v-if="scope.row.isCloseOverdue == 'N'">否</span>
              <span v-if="scope.row.isCloseOverdue == 'Y'">是</span>
            </template>
          </el-table-column>
          <el-table-column label="是否缴费开阀" align="center" key="isOpenPaid" prop="isOpenPaid" :show-overflow-tooltip="true"
            width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.isOpenPaid == 'N'">否</span>
              <span v-if="scope.row.isOpenPaid == 'Y'">是</span>
            </template>
          </el-table-column>
          <el-table-column label="短信提醒号码" align="center" key="messagePhone" prop="messagePhone"
            :show-overflow-tooltip="true" width="120" />
          <el-table-column label="开户日期" align="center" key="openDate" prop="openDate" :show-overflow-tooltip="true" />
          <!-- <el-table-column label="充值次数" align="center" key="payCount" prop="payCount" :show-overflow-tooltip="true" /> -->
          <el-table-column label="联系电话" align="center" key="telephone" prop="telephone" :show-overflow-tooltip="true" />
          <el-table-column label="备注" align="center" key="remark" prop="remark" :show-overflow-tooltip="true" />
        </el-table>
        <pagination v-show="total1 > 0" :total="total1" :page.sync="queryParams1.pageNum"
          :limit.sync="queryParams1.pageSize" @pagination="getList" />
      </el-dialog>
    </el-dialog>

  </div>
</template>

<script>
import {
  listPost,
  getPost,
  delPost,
  addPost,
  updatePost,
} from "@/api/system/post";
import { areaList } from "@/api/fileManagement/areainfo.js"
import { meterarchivesList, meterarchivesInfo, addMeterarchives, updateMeterarchives, delMeterarchives } from "@/api/fileManagement/meterarchives.js"
import { customeList, generateNumber } from "@/api/fileManagement/civilArchives.js"
import { getSupplierList } from '@/api/system/supplierInfo.js'
import { getGasmeterList } from '@/api/systemSetup/gasMeter.js'
import { planSelectList, } from '@/api/service/planlist.js'
export default {
  name: "TableArchives",
  dicts: ["sys_normal_disable", "customer_type"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total1: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      open2: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerName: null,
        imei: null,
        meterType: null,
      },
      queryParams1: {
        pageNum: 1,
        pageSize: 10,
        customerType: null,
        customerName: null,
        customerCode: null,
        telephone: null,


      },
      queryParams2: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        customerName: [
          { required: true, message: "客户名称不能为空", trigger: "blur" },
        ],
        meterCode: [
          { required: true, message: "表号不能为空", trigger: "blur" },
        ],
        meterManufacturer: [
          { required: true, message: "供应商不能为空", trigger: "change" },
        ],
        priceSchemeId: [
          { required: true, message: "计价方案不能为空", trigger: "change" },
        ],
        meterStatus: [
          { required: true, message: "表计状态不能为空", trigger: "change" },
        ],
        meterType: [
          { required: true, message: "表计类型不能为空", trigger: "change" },
        ]
        // postName: [
        //   { required: true, message: "岗位名称不能为空", trigger: "blur" },
        // ],
        // postCode: [
        //   { required: true, message: "岗位编码不能为空", trigger: "blur" },
        // ],
        // postSort: [
        //   { required: true, message: "岗位顺序不能为空", trigger: "blur" },
        // ],
      },
      supplierList: [],
      // 小区表格数据
      userList: null,
      meterList: [],
      schemeList: [],
      meterBySupplierList: [],
      disStatus: false,
    };
  },
  created() {
    this.getMeterList()
    this.getsupplierList()
    this.getPricingPlanList()
    setTimeout(() => {
      this.getList();
    }, 200)

  },
  methods: {
    // // 刷新客户编码
    // refreshNumber() {
    //   this.getNumber()
    // },
    // // 获取客户编码
    // getNumber() {
    //   generateNumber('22').then((res) => {
    //     // this.form.customerCode = res.data
    //     this.$set(this.form, 'meterCode', res.data)
    //   })
    // },
    // 获取表计类型
    getMeterList() {
      getGasmeterList().then((res) => {
        this.meterList = res.data
      })
    },
    // 供应商选择后获取表计类型
    getMeterListBySupplier() {
      this.$set(this.form, 'meterType', '')
      getGasmeterList({ manufacturerId: this.form.meterManufacturer }).then((res) => {
        this.meterBySupplierList = res.data
      })
    },
    /** 查询小区列表 */
    getcustomeList() {
      this.loading = true;
      customeList(this.queryParams1).then((response) => {
        this.userList = response.rows;
        this.total1 = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm1");
      this.queryParams.deptId = undefined;
      this.handleQuery();
    },
    // 弹出客户列表
    customerSerch() {
      this.open1 = true
      this.getcustomeList()

    },
    // 查询计价方案
    getPricingPlanList() {
      planSelectList().then((res) => {
        this.schemeList = res
      })
    },
    /** 查询供应商列表 */
    getsupplierList() {
      let params = {
        pageNum: 1,
        pageSize: 9999,
      }
      getSupplierList(params).then((response) => {
        this.supplierList = response.data;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/meterarchives/export",
        {
          ...this.queryParams,
        },
        `user_${new Date().getTime()}.xlsx`
      );
    },
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      meterarchivesList(this.queryParams).then((response) => {
        if (response.code == 200) {
          let list = JSON.parse(JSON.stringify(response.rows))
          list.map((res) => {
            this.meterList.map((item) => {
              if (res.meterType == item.id) {
                res.meterType = item.typeName
              }
            })
            this.supplierList.map((res1) => {
              if (res.meterManufacturer == res1.id) {
                res.meterManufacturer = res1.supplierName
              }
            })
          })
          this.postList = list
          this.total = response.total;
          this.loading = false;
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        postId: undefined,
        postCode: undefined,
        postName: undefined,
        postSort: 0,
        status: "0",
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleQuery1() {
      this.queryParams1.pageNum = 1;
      this.getcustomeList();
    },
    resetQuery1() {
      this.resetForm("queryForm1");
      this.getcustomeList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.postId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    // 选中表格
    rowSelectionChange(row) {
      this.form.customerName = row.customerName
      this.form.customerId = row.id
      this.form.meterType = row.meterType
      this.open1 = false
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.disStatus = false
      this.reset();
      this.open = true;
      this.title = "新增表计档案";
      this.form = {
        meterType: '',
        intakeDirection: "L",

      }
      // this.getNumber()
      this.getsupplierList()
      // this.getMeterListBySupplier()
      this.getPricingPlanList()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getsupplierList()
      // this.getMeterListBySupplier()
      this.getPricingPlanList()
      const postId = row.id;
      meterarchivesInfo(postId).then((response) => {
        getGasmeterList({ manufacturerId: response.data.meterManufacturer }).then((res) => {
          this.meterBySupplierList = res.data
        })
        this.form = response.data;
        if (response.data.activeStatus == 'Y') {
          this.disStatus = true
        } else {
          this.disStatus = false
        }
        this.open = true;
        this.title = "修改表计档案";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            updateMeterarchives(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMeterarchives(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const postIds = row.meterCode;
      this.$modal
        .confirm('是否确认删除表号为"' + postIds + '"的数据项？')
        .then(function () {
          return delMeterarchives(postIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
  },
};
</script>
